home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / pthd-0.000 / pthd-0 / pthd-0.7 / src_signals / exc_test.c next >
Encoding:
C/C++ Source or Header  |  1995-08-16  |  1.2 KB  |  74 lines

  1. /*
  2.  * exc_test.c
  3.  */
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <pthread.h>
  7. #include "exc_handling.h"
  8.  
  9. EXCEPTION MyExc;
  10.  
  11. static void 
  12. foo( void )
  13. {
  14.    RAISE( MyExc );
  15. }
  16.  
  17. void bar( void )
  18. {
  19.     TRY
  20.         foo();
  21.     CATCH_ALL
  22.         pthread_lock_global_np();
  23.         printf("Child caught exception!\n");
  24.         pthread_unlock_global_np();
  25.     ENDTRY
  26.  
  27.     pthread_exit( (void *)SUCCESS );
  28. }
  29. static pthread_t th;
  30.  
  31. int main()
  32. {
  33.    int st = 0, *p;
  34.  
  35.    EXCEPTION_INIT( MyExc );
  36.  
  37.    TRY
  38.        pthread_lock_global_np();
  39.        p = malloc( sizeof( p ));
  40.        pthread_unlock_global_np();
  41.  
  42.        TRY
  43.  
  44.             (void) pthread_create( &th, 
  45.                                    pthread_attr_default,
  46.                                    (pthread_startroutine_t) bar,
  47.                                    NULL );
  48.  
  49.            (void) pthread_join( th, (void **) &st );
  50.            pthread_lock_global_np();
  51.            fprintf( stderr, "child exited with %d status!\n", st );
  52.            pthread_unlock_global_np();
  53.  
  54.        FINALLY
  55.  
  56.            free( p );
  57.            pthread_lock_global_np();
  58.            fprintf( stderr, "Deallocated p\n");
  59.            pthread_unlock_global_np();
  60.  
  61.        ENDTRY
  62.  
  63.    CATCH_ALL
  64.  
  65.        pthread_lock_global_np();
  66.        fprintf(stderr, "Caught an error!\n");
  67.        pthread_unlock_global_np();
  68.  
  69.    ENDTRY
  70.  
  71.    return( EXIT_SUCCESS );
  72. }
  73.  
  74.